package com.atguigu.gmall.controller;

import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

//@Controller//Controller的注解
@RestController // @Controller+
@Slf4j
public class LoggerController {
    @Autowired
    private KafkaTemplate<String,String> kafkaTemplate;
    @RequestMapping("test1")
    public String test1(){
        System.out.println("successs");
        return "index";
    }
    @RequestMapping("test2")
    public String test2(@RequestParam("name") String nn,
                        @RequestParam(value = "age",defaultValue = "18") int age){
        System.out.println(nn+":"+age);
        return "index";
    }
    @RequestMapping("applog")
    public String getLog(@RequestParam("param") String jsonStr){
        //打印数据
//        System.out.println(jsonStr);

        //将数据落盘
        log.info(jsonStr);

        //写入kafka
        kafkaTemplate.send("ods_base_log",jsonStr);


        return "success";
    }

}
